<?php
function SelectForm($SelectName,$object,$ValueField,$TextField,$SelectValue="")
{
    $Str  =    "<select class='text-input small-input' name=".$SelectName." id = ".$SelectName.">\r\n";
    //$Str  =    $Str."<option value=\"0\" >请选择...</option>\r\n";
    foreach($object as $key)
    {
        $Str = $Str.'<option value="'.$key->$ValueField.'"';
        $Str = $Str.Selected($key->$ValueField,$SelectValue);
            $Str = $Str.'>'.$key->$TextField.'</option>'."\r\n";
    }
    $Str  = $Str."</select>\r\n";
    return $Str;
}

function selectClassName($SelectName,$object,$ValueField,$TextField,$SelectValue="")
{
    $object_arr = $object;
    $Str  =    "<select class='text-input small-input' name=".$SelectName." id = ".$SelectName.">\r\n";
    $Str  =    $Str."<option value=\"0\" >作为一级分类</option>\r\n";
    foreach($object as $key)
    {
        if ($key['pid']==0)
        {
            $Str = $Str.'<option value="'.$key[$ValueField].'"';
            $Str = $Str.Selected($key["$ValueField"],$SelectValue);
            $Str = $Str.'>|-'.$key[$TextField].'</option>'."\r\n".fenlei($object,$key['id'],$SelectValue);      
        }
    }
    $Str  = $Str."</select>\r\n";
    return $Str;    
}

function fenlei($objetArr,$f_id=0,$SelectValue,$htmls="",$htmlper="|-"){  
    foreach ($objetArr as $key)
    {
        if($objetArr['pid']!='0')
        {
            if($key['pid']==$f_id)
            {          
                $htmlper=$htmlper.'-';
                $htmls = $htmls.'<option value="'.$key['id'].'"';
                $htmls = $htmls.Selected($key["id"],$SelectValue);
                $htmls = $htmls.'>'.$htmlper.$key['classname'].'</option>'."\r\n";
                $htmls = fenlei($objetArr,$key['id'],$SelectValue,$htmls,$htmlper);   
            }
        }
    }
    return $htmls;
}

function Selected($str1,$str2,$s="Selected")
{
    if($str1 == $str2)
        return $s;
}

function Checkbox($id,$valueS,$checkStr)
{
    $str = "<input type=\"checkbox\" id=".$id." name=".$id."  value=".$valueS."  ".Selected($valueS,$checkStr,'checked')."/>";
    return $str;
}

function selectdataType($id,$valueS="")
{
    $dataTypeArr = array('int'=>'int','varchar'=>'varchar(20)','date'=>'date','datetime'=>'datetime','text'=>'text');
    $str  =    "<select class='text-input small-input' name=".$id." id = ".$id.">\r\n";
    $str = $str.'<option value="" >未知</option>';
    foreach($dataTypeArr as $k=>$v)
    {
        $str = $str.'<option value="'.$v.'"  '.Selected($valueS,$v).'>'.$k.'</option>';
    }
    $str  = $str."</select>\r\n";
    return $str;
}

function selectHtmlType($id,$valueS="")
{
    $htmlTypeArr = array('text'=>'text','check'=>'check','select'=>'select','file'=>'file','textarea'=>'textarea','hiden'=>'hiden');
    $str  =    "<select class='text-input small-input' name=".$id." id = ".$id.">\r\n";
    $str = $str.'<option value="" >未知</option>';
    foreach($htmlTypeArr as $k=>$v)
    {
        $str = $str.'<option value="'.$v.'"  '.Selected($valueS,$v).'>'.$k.'</option>';
    }
    $str  = $str."</select>\r\n";
    return $str;    
}
?>
